package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.query.DestinationQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//目的地后端控制器
@Controller
@RequestMapping("/destination")
public class DestinationController {

    @Autowired
    private IDestinationService destinationService;

    /**
     * 高查
     * @param model
     * @param qo
     * @return
     */
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo")DestinationQuery qo) {
        //高查(加入导航吐司条件进行高查)
        model.addAttribute("page",destinationService.query(qo));
        //提供导航吐司数据
        model.addAttribute("toasts",destinationService.queryToasts(qo.getParentId()));
        return "/destination/list";
    }

    /**
     * 删除功能
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id) {
        destinationService.delete(id);
        return JsonResult.success();
    }

    /**
     * 修改目的地简介
     * @param id
     * @return
     */
    @RequestMapping("/updateInfo")
    @ResponseBody
    public JsonResult updateInfo(String id,String info) {
        destinationService.updateInfo(id,info);
        return JsonResult.success();
    }

}

